<?php

namespace App\Entities;

class OrderCancelEntity extends ABaseEntity
{
    public function __construct(OrderCancelModel $model)
    {
        $this->model = $model;
    }

    /**
     * @param int $orderId
     * @return OrderCancelEntity|null
     */
    public static function findByOrderId(int $orderId)
    {
        $orderRefund = OrderCancelModel::where('order_id', '=', $orderId)
            ->orderBy('id', 'desc')
            ->first();
        if (is_null($orderRefund)) {
            return null;
        }
        return new self($orderRefund);
    }

    /**
     * @return int
     */
    public function getId()
    {
        return (int)$this->model->id;
    }

    /**
     * @param int $orderId
     */
    public function setOrderId(int $orderId)
    {
        $this->model->order_id = $orderId;
    }

    /**
     * @return int
     */
    public function getOrderId()
    {
        return (int)$this->model->order_id;
    }

    /**
     * 用户ID
     * @param int $userId
     */
    public function setUserId(int $userId)
    {
        $this->model->user_id = $userId;
    }

    /**
     * 用户ID
     * @return int
     */
    public function getUserId()
    {
        return (int)$this->model->user_id;
    }

    /**
     * @param string $reason
     */
    public function setReason(string $reason): void
    {
        $this->model->reason = $reason;
    }

    /**
     * @return string
     */
    public function getReason(): string
    {
        return $this->model->reason;
    }
}
